package cn.ubeta.b2c.navigation;

import android.text.TextUtils;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import cn.ubeta.b2c.EmbeddedData;
import cn.ubeta.b2c.R;
import cn.ubeta.b2c.bean.FoundInfo;
import cn.ubeta.b2c.common.ListFragment;
import cn.ubeta.b2c.common.ListFragmentConfig;
import cn.ubeta.b2c.product.ProductListActivity;
import cn.ubeta.b2c.widget.recyclerview.BaseViewHolder;

import java.util.List;

import static cn.ubeta.b2c.product.ProductListFragment.setResImage;

/**
 * Created by denny on 16/8/17.
 */

public class FoundFragment extends ListFragment<FoundInfo> {

    @Override
    protected ListFragmentConfig getConfig() {
        return new ListFragmentConfig(R.layout.item_found);
    }

    @Override
    protected void bindItemView(BaseViewHolder helper, FoundInfo item) {
        // 商品图片
        SimpleDraweeView img = helper.getView(R.id.iv_product);
        setResImage(img, item.getResImg(), false);
        if (item.getBrandId() != 0) {
            img.setOnClickListener(v -> ProductListActivity.gotoProductList(getActivity(), item.getName(), item.getBrandId()));
        }
        // 商品标题
        String name = item.getName();
        if (!TextUtils.isEmpty(name)) {
            ((TextView) helper.getView(R.id.tv_name)).setText(name);
        }
        // 添加购物车
        //helper.getView(R.id.tv_add_cart).setOnClickListener(v -> CartCommon.add2Cart(item.getBrandId()));
    }

    @Override
    protected void loadData(int page) {
        //ApiTopic.getTopicList(getNetworkCallback());
        List<FoundInfo> data = EmbeddedData.getBrands(true);
        getNetworkCallback().onResponse(data);
    }

}
